package com.hzl;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yao.component.circle.R;

/**
 * Created by Administrator on 2015/11/2.
 */
public class AlertDialog extends Dialog {
    Context context;
    android.app.AlertDialog ad;
    TextView titleView;
    TextView messageView;
    LinearLayout buttonLayout;
    private  TextView quxiao = null;
    private  TextView queding = null;


    public AlertDialog(Context context) {
        // TODO Auto-generated constructor stub
        super(context);
        this.context=context;
        ad=new android.app.AlertDialog.Builder(context).create();
        ad.show();
        //关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
        Window window = ad.getWindow();
        window.setContentView(R.layout.alertdialog);
        titleView=(TextView)window.findViewById(R.id.title);
        messageView=(TextView)window.findViewById(R.id.message);
//        quxiao = (TextView) window.findViewById(R.id.quxiao);
        queding = (TextView) window.findViewById(R.id.queding);

    }


//    public void setTitle(int resId)
//    {
//        titleView.setText(resId);
//    }
    public void setTitle(String title) {
        titleView.setText(title);
    }
//    public void setMessage(int resId) {
//        messageView.setText(resId);
//    }
    public void setMessage(String message)
    {
        messageView.setText(message);
    }
    /**
     * 设置按钮
     * @param text
     * @param listener
     */
    public void setPositiveButton(String text,final View.OnClickListener listener)
    {
//        Button button=new Button(context);
//        LinearLayout.LayoutParams params=
//                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//        button.setLayoutParams(params);
//        button.setBackgroundResource(R.drawable.alertdialog_button);
//        button.setText(text);
//        button.setTextColor(Color.WHITE);
//        button.setTextSize(20);
        queding.setOnClickListener(listener);
//        buttonLayout.addView(button);
    }  /**
     * 设置按钮
     * @param text
     * @param listener
     */
    public void setNegativeButton(String text,final View.OnClickListener listener)
    {
        quxiao.setOnClickListener(listener);
//        Button button=new Button(context);
//        LinearLayout.LayoutParams params=
//                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//        button.setLayoutParams(params);
//        button.setBackgroundResource(R.drawable.alertdialog_button);
//        button.setText(text);
//        button.setTextColor(Color.WHITE);
//        button.setTextSize(20);
//        button.setOnClickListener(listener);
//        if(buttonLayout.getChildCount()>0)
//        {
//            params.setMargins(20, 0, 0, 0);
//            button.setLayoutParams(params);
//            buttonLayout.addView(button, 1);
//        }else{
//            button.setLayoutParams(params);
//            buttonLayout.addView(button);
//        }
    }
    /**
     * 关闭对话框
     */
    public void dismiss() {
        ad.dismiss();
    }


}
